package com.lx.util.exception;

import com.lx.entity.Result;

/**
 * 指定返回code 的异常
 * @author 86158
 */
public class ResultServiceException extends ServiceException {

    private Result result;

    public static void exMsg(String msg){
        throw  new ResultServiceException(msg);
    }

    //说明: 抛出异常
    /**{ ylx } 2020/9/21 17:11 */
    public static void exMsg(String msg, int statusCode){
        throw new ResultServiceException(msg, statusCode);
    }

    public ResultServiceException(Result result) {
        super(result.getMessage());
        this.result = result;
    }
    public ResultServiceException(Throwable e, int statusCode) {
        super(e);
        this.result = new Result<>(statusCode);
    }

    public ResultServiceException(String msg) {
        super(msg);
        this.result = Result.err(msg);
    }
    public ResultServiceException(String msg, int statusCode) {
        super(msg);
        this.result = Result.err(statusCode, msg);
    }

    public ResultServiceException(String msg, Object data, int statusCode) {
        super(msg);
        this.result = new Result<>(statusCode,msg,data);
    }

    public Result getResult() {
        return result;
    }
}
